package Niuke;


import com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI;
import sun.tools.jconsole.MaximizableInternalFrame;

import java.util.HashMap;
import java.util.Stack;

public class test {


    public static void printYTC(int[][] matrix){
        int x1=0;
        int y1=0;
        int x2=0;
        int y2=0;
        int Yend= matrix[0].length-1;
        int Xend= matrix.length-1;
        boolean flag=false;
        while (x1<=Xend){
            printLevelYTC(matrix,x1,y1,x2,y2,flag);
            x1=y1==Yend?x1+1:x1;
            y1=y1==Yend?y1:y1+1;
            y2=x2==Xend?y2+1:y2;
            x2=x2==Xend?x2:x2+1;
            flag=!flag;
        }
        System.out.println();
    }
    public static void printLevelYTC(int[][] matrix,int x1, int y1,int x2,int y2,boolean flag){
        if (flag){
            while (x1!=x2+1){
                System.out.print(matrix[x1++][y1--]+" ");
            }
        }else {
            while (x2!=x1-1){
                System.out.print(matrix[x2--][y2++]+" ");
            }
        }
    }

    public static void main(String[] args) {
        int[][] matrix = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } };
        //1  2  3   4
        //5  6  7   8
        //9  10  11   12
        //printMatrixZigZag(matrix);
        printYTC(matrix);

    }
}
